/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openmrs.module.basicmodule.DSS.Interpreter;

import org.openmrs.module.basicmodule.DSS.ast.AST;

/**
 *
 * @author Stephen
 */
public class NotEqualsOperator {
    private AST t;
    private InterpreterVisitor iv;

    public NotEqualsOperator(AST t, InterpreterVisitor iv) {
        this.t = t;
        this.iv = iv;
    }

    public Object execute() {
        Object operand1 = t.getKid(1).accept(iv);
        Object operand2 = t.getKid(2).accept(iv);
        String type = InterpreterVisitor.parseType((String) operand1);

        if (type.equalsIgnoreCase("float")) {
            return (Float.parseFloat((String) operand1) != (Float.parseFloat((String) operand2)));
        } else if (type.equalsIgnoreCase("int")) {
            return (Integer.parseInt((String) operand1) != (Integer.parseInt((String) operand2)));
        } else if (type.equalsIgnoreCase("string")) {
            return (!((String)operand1).equals((String)operand2));
        } else {
            return (operand1 != operand2);
        }
    }
}
